package com.lych.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lych.dubbo.mappers.BlackListMapper;
import com.lych.dubbo.mappers.SettingsMapper;
import com.lych.dubbo.mappers.UserInfoMapper;
import com.lych.model.domain.BlackList;
import com.lych.model.domain.Settings;
import com.lych.model.domain.UserInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class SettingsApiImpl implements SettingsApi {

    @Autowired
    private SettingsMapper settingsMapper;

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Autowired
    private BlackListMapper blackListMapper;

    @Override
    public Settings findById(Long userId) {
        LambdaQueryWrapper<Settings> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Settings::getUserId,userId);
        return settingsMapper.selectOne(lqw);
    }

    /**
     * 通知设置 - 保存
     * @param settings
     */
    @Override
    public void save(Settings settings) {
        settingsMapper.insert(settings);
    }

    /**
     * 通知设置 - 修改
     * @param settings
     */
    @Override
    public void update(Settings settings) {
        settingsMapper.updateById(settings);
    }

    /**
     * 黑名单 - 翻页列表
     * @param userId
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<UserInfo> findByUserId(Long userId, int page, int size) {
        //分页构造器
        Page<UserInfo> userInfoPage = new Page<>(page,size);
        //调用方法分页（自定义编写 分页参数Page，sql条件参数）
        return userInfoMapper.findBlackList(userInfoPage,userId);
    }

    /**
     * 黑名单 - 移除
     * @param userId
     * @param blackUserId
     */
    @Override
    public void blacklistDelete(Long userId, Long blackUserId) {
        //条件构造器
        LambdaQueryWrapper<BlackList> lqw = new LambdaQueryWrapper<>();
        lqw.eq(BlackList::getUserId,userId);
        lqw.eq(BlackList::getBlackUserId,blackUserId);

        blackListMapper.delete(lqw);
    }


}
